//
//  E7Cell.cpp
//  EndlessBattle
//
//  Created by cc on 12-3-17.
//  Copyright (c) 2012年 PalmGame. All rights reserved.
//

#include "E7Cell.h"

#include "E7Logic.h"

CE7Cell::CE7Cell()
{
    m_nID = -1 ;
    m_nNeighborCount = -1 ;

//    CCPoint     m_posBorders[6] ;
//    CCPoint     m_posCenter ;

//    CE7Cell*    m_pNeighbors[6] ;
    for (int i = 0; i < 6; ++i)
    {
        m_pNeighbors[i] = NULL ;
    }

    m_nCountryID = -1 ;
    m_nTownID = -1 ;
    m_nUnitID = -1 ;
    m_nUnitValue = UV_NONE ;
    m_nToNeighborUV = UV_NONE ;

    m_eDebugUV = UV_NONE ;
}

CE7Cell::~CE7Cell()
{
}

void CE7Cell::UpdateUV()
{
    if (m_nUnitID != -1)
    {
        CE7Unit* pUnit = s_pLogic->GetSelectUnitInfo(m_nUnitID) ;
        if (NULL == pUnit)
        {
            printf("CE7Cell::UpdateUV NULL == pUnit [%d]\n", m_nUnitID) ;
            printf("CE7CELL UpdateUV debug mode unit info: [%lu][%d][%d]\n",
                   s_pLogic->m_listUnit.size(), s_pLogic->create_unit_count, s_pLogic->delete_unit_count) ;
//            return ;
        }
        m_nToNeighborUV = pUnit->GetUV() ;
        m_nUnitValue = m_nToNeighborUV ;
    }
    else
    {
        m_nToNeighborUV = UV_NONE ;
        m_nUnitValue = UV_NONE ;
    }

    for (int i = 0; i < 6; ++i)
    {
        if (NULL != m_pNeighbors[i] &&
            m_nCountryID == m_pNeighbors[i]->GetCountryID())
        {
            if (m_pNeighbors[i]->GetUV() < m_nToNeighborUV)
            {
                m_pNeighbors[i]->SetUV(m_nToNeighborUV) ;
            }
            else
            {
                if (m_pNeighbors[i]->GetToNeighborUV() > m_nUnitValue)
                {
                    m_nUnitValue = m_pNeighbors[i]->GetToNeighborUV() ;
                }
            }
        }
    }
}




















